import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:qaun_ni_dev/utils/toast.dart';
import 'package:qaun_ni_dev/utils/request.dart';
import 'package:qaun_ni_dev/model/real_name_model.dart';


class RealNameProvider with ChangeNotifier {

  String realCheckUrl = '';
  int page = 1;
  List<RealNameData> realNameListData = [];

  getRealNameList(context) async{
    page = 1;
    realNameListData = [];
    var formData = {
      'currentPage': page,
    };
    await requestPost(context, '/check/realCheckList',formData: formData).then((value){
      var res = json.decode(value.toString());
      var tempData = RealNameModel.fromJson(res);
      if(tempData.data.length > 0) {
        realNameListData = tempData.data;
      } else {
        return Toast.toast(context,msg: '暂无数据');
      }
      notifyListeners();
    });
  }

  getRealNameMoreList(context) async{
    page++;
    var formData = {
      'currentPage': page,
    };
    await requestPost(context, '/check/realCheckList',formData: formData).then((value){
      var res = json.decode(value.toString());
      var tempData = RealNameModel.fromJson(res);
      if(tempData.code == 200) {
        var tempMoreData = tempData.data;
        if(tempMoreData.length > 0 ) {
          realNameListData.addAll(tempMoreData);
        } else {
          Toast.toast(context,msg: '已经没有更多数据了哦！');
        }
      }
    });
    notifyListeners();
  }



  isAgreeUser(context,formData)async {
    await requestPost(context, '/check/realCheck',formData: formData).then((value){
      var res = json.decode(value.toString());
      if(res['code'] == 200) {
        Toast.toast(context,msg: '操作成功');
        Navigator.pushNamed(context, '/realName');
      } else {
        Toast.toast(context,msg: '操作失败了,请重试');
        Navigator.pushNamed(context, '/realName');
      }
    });

    notifyListeners();
  }

  getRealNameVideoUrl (url) {
    realCheckUrl = url;
    notifyListeners();
  }
}


